﻿/// <reference path="../../../fly.common/fly/fly.js" />
!function () {
    var $ = fly;
    setInterval(function () {
        if (document.body)
            window.frameElement.style.height =Math.max(document.documentElement.scrollHeight, document.body.scrollHeight )+ 'px'
    }, 100)

    $.box.FileMore = $.Class({
        current: 'tags',
        constructor: function () {
            this.createMembers();
            this.bindEvents();
            this.init();
        },
        init: function () {
            $.post(fly.box.ajaxUrl('SpaceFileEx', 'GetFileExInfos'), {
                fileId: this.fileId,
                keys: 'Tags,Summary'
            }, function (result) {
                if (result.success) {
                    $.each(result.data, function (v, k) {
                        $('#' + k.camelCase()).val(v)
                    })
                }
                else
                    $.alert(result.msg)
            })
        },
        createMembers: function () {
            this.fileId = $.getQuery('fileId')
            this.topBar = $('#top-bar');
        },
        bindEvents: function () {
            var me = this;
            this.topBar.find('a').click(function () {
                $.getBody()[0].className = me.current = this.id.replace('a-', '');
            })
        },
        submit: function () {
            function success(result) {
                if (result.success)
                    frameElement.close()
                else
                    $.alert(result.msg || '保存失败。')
            }

            if (this.current == 'tags') {
                $.post(fly.box.ajaxUrl('SpaceFileEx', 'SetTags'), {
                    fileId: this.fileId,
                    tags: $('#tags').val()
                }, success)
            }
            else {
                $.post(fly.box.ajaxUrl('SpaceFileEx', 'SetSummary'), {
                    fileId: this.fileId,
                    summary: $('#summary').val()
                }, success)
            }
        }
    });

    $(function () {
        window.fileMore = new $.box.FileMore();
    });
} ()